package com.delayqueue.core.permanent;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.io.File;

@Configuration
@ConfigurationProperties("permanent")
@Setter
@Getter
public class PermanentConfig {

    //是否开启持久化
    private Boolean enabled = true;
    //是否异步刷盘
    private Boolean async = false;
    //持久化文件目录
    private String dataDir;
    //是否开启归档
    private Boolean archive = true;
    //每个归档文件的最大长度（KB）
    private long archiveMaxFileSize = 1024;
    //垃圾清理间隔（分钟）
    private int cleanTaskInterval = 60;
    //归档目录
    private String archiveDirPath;

    public void setDataDir(String dataDir) {
        this.dataDir = dataDir;
        if (enabled) {
            File dir = new File(dataDir);
            dir.mkdirs();
            if (archive) {
                archiveDirPath = dataDir + "/archive";
            }
        }
    }

    //获取字节单位的文件大小
    public long getArchiveMaxFileSize() {
        return archiveMaxFileSize * 1024;
    }
}
